import 'package:flutter/material.dart';
import 'package:xiongan_app_yy/entrys/rp/inv_list_entity.dart';

class HomeItemInfo extends StatefulWidget {
  InvListData _data;
  int index;
  Function function;

  HomeItemInfo(this._data, this.index, this.function);

  @override
  _HomeItemInfoState createState() => _HomeItemInfoState();
}

class _HomeItemInfoState extends State<HomeItemInfo> {
  String stateString;
  Color textColor;
  List routeList = [
    "/invListItemDetails",
    "/deliveryListDetails",
    "/return_booking_detail",
    "/invListItemDetails",
    '/deliveryDatailsList'
  ];

  List type = [
    "出库预约单",
    "配送预约单",
    "工程结余退库预约单",
    "入库预约单",
    "调配预约单",
  ];

  List names = [
    "出库预约单",
    "配送预约单",
    "结余退库预约单",
    "入库预约单",
    "调配预约单",
  ];

  @override
  Widget build(BuildContext context) {
    if (widget._data.state == "未分配") {
      stateString = "未审核";
      textColor = Color(0xFF00A5F1);
    } else if (widget._data.state == "未审批") {
      stateString = "未审核";
      textColor = Color(0xFF00A5F1);
    } else if (widget._data.state == "未入库" || widget._data.state == "未出库") {
      stateString = "审核通过";
      textColor = Color(0xFF2FC480);
    } else if (widget._data.state == "已入库" || widget._data.state == "已出库") {
      stateString = "审核通过";
      textColor = Color(0xFF2FC480);
    } else if (widget._data.state == "待执行" ) {
      stateString = "审核通过";
      textColor = Color(0xFF2FC480);
    }  else if (widget._data.state == "已驳回") {
      stateString = "审核未通过";
      textColor = Color(0xffF5BD36);
    }else if (widget._data.state == "已废弃"||widget._data.state == "已作废") {
      stateString = "已废弃";
      textColor = Color(0xFFFB4747);
    }
    return GestureDetector(
      onTap: () {
        Navigator.pushNamed(context, routeList[widget.index], arguments: {
          "id": widget._data.id,
          "type": type[widget.index],
          "state": stateString
        }).then((value) {
          if (value == "ok") {
            widget.function();
          }
        });
      },
      child: Container(
        color: Colors.white,
        child: Column(
          children: <Widget>[
            ConstrainedBox(
              constraints:
                  BoxConstraints.expand(width: double.infinity, height: 84),
              child: Stack(
                children: <Widget>[
                  Positioned(
                    top: 10,
                    left: 10,
                    width: 66,
                    height: 66,
                    child: Image.asset(
                      "assets/images/real_background.png",
                      fit: BoxFit.fill,
                    ),
                  ),
                  Positioned(
                    child: Text(
                      "司机：${widget._data.driver ?? ""}",
                      style: TextStyle(
                        color: Color(0xff646464),
                        fontSize: 16,
                      ),
                    ),
                    left: 90,
                    top: 10,
                  ),
                  Positioned(
                    child: Text(
                      "预约类型：${names[widget.index]}",
                      style: TextStyle(
                        color: Color(0xff646464),
                        fontSize: 16,
                      ),
                    ),
                    left: 90,
                    bottom: 10,
                  ),
                  Positioned(
                    right: 12,
                    top: 32,
                    width: 8,
                    height: 16,
                    child: Image.asset(
                      "assets/images/arrow.png",
                      fit: BoxFit.fill,
                    ),
                  ),
                ],
              ),
            ),
            Container(
              padding: EdgeInsets.only(left: 10, right: 10),
              child: Divider(height: 2, color: Color(0xffeeeeee)),
            ),
            Row(
              children: <Widget>[
                Expanded(
                    child: Padding(
                  padding: EdgeInsets.only(top: 8, bottom: 8, left: 10),
                  child: Text(
                    stateString,
                    style: TextStyle(
                      color: textColor,
                      fontSize: 14,
                    ),
                  ),
                )),
                Padding(
                  padding: EdgeInsets.only(top: 8, bottom: 8, right: 10),
                  child: Text(
                    "${widget._data.creationTime}",
                    style: TextStyle(
                      color: Color(0xff989898),
                      fontSize: 14,
                    ),
                  ),
                ),
              ],
            )
          ],
        ),
      ),
    );
  }
}
